//销售方案·分布销售
(function(){
	var db = require("../db/index");
	var config = require("../_include/config");
	var db_table_name = config.dbname.marketStep;
	var db_id_prefix = config.dbIdPrefix.marketStep;
	var helper = require("../_include/helper");

	//构造函数
	var _con = function (market_name,if_infos,result_infos){
		var self = this;
		//ID编号
		self._id = db_id_prefix+Math.random().toString(16).substr(2)+(+new Date).toString(16);
		//销售方案的名称
		self.market_name = market_name;
		//触发条件信息
		if(!if_infos){
			throwCusError("条件不可为空")
		}
		self.if_infos = if_infos;
		//触发结果
		self.result_infos = result_infos||[];
		
		db.insert(db_table_name,self);
		console.log("创建一个销售方案：",market_name);
	};
	//PS:模块的暴露放在require skill前面，因为二者互相依赖
	module.exports = _con;
	//技能
	_con.prototype = require("./skill");

	//静态方法
	_con.get = function(Id){
		var result = db.find_by_id(db_table_name,Id);
		if(result){
			result.__proto__ = _con.prototype;
		}
		return result;
	};
}());
